/* 函数节流 */
function throttle (func, delay) {
  let last
  let deferTimer
  return function () {
    let _args = arguments
    let now = +new Date()
    if (last && now < last + delay) {
      clearTimeout(deferTimer)
      deferTimer = setTimeout(() => {
        last = now
        func.apply(this, _args)
      }, delay)
    } else {
      last = now
      func.apply(this, _args)
    }
  }
}

export default throttle
